package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author:石小俊
 * @Date:2022/12/12 9:28
 * @Version:1.0-SNAPSHOT
 * @Description: 通配符配置,此时的url-pattern的值不能以/开头
 *  表示只要请求以.test结尾均能访问当前Servlet
 */
@WebServlet("*.test")
public class TestTwoServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();

        String path = request.getServletPath();
        // 此时path的值是应用名后面所有的地址
        System.out.println("servletPath:"+path);

        out.print("<h1 style='color:green;'>这是第二种通配符的使用方式</h1>");
    }

}
